﻿#ifndef DB_H
#define DB_H

#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QDir>
#include <QFile>
#include <QApplication>
#include <QMap>
#include <memory>
#include <QString>

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "lah/Struct_cv.h"

#include "seeta/FaceRecognizer.h"
#include "seeta/FaceDetector.h"
#include "seeta/FaceLandmarker.h"

class DB
{
public:
    DB();
    QSqlDatabase database;
    void init();
    void openDb();
    void closeDb();
    bool execSql(QString stringSql);
    QMap<QString, QString> queryById(QString userId); //people_t
    QMap<QString, QString> queryUserById(QString userId); //user_t
    QMap<QString, QMap<QString, QString>> querLoginlogByTimeAndId(QString startTime, QString endTime, QString userId);

    bool insertLoginlog(QString time, QString id, QString result, QString IP);
    bool updateRegist(QString userId, QString idCardImagePath);
    bool updateAction(QString userId, QString action);
    bool updateEmotion(QString userId, QString emotion);

    QMap<QVector<QString>,std::shared_ptr<float>> getAllFace(seeta::FaceRecognizer* FR, seeta::FaceLandmarker* FLM5, seeta::FaceDetector* FD);
    std::shared_ptr<float> extract(
                seeta::FaceRecognizer* fr,
                const seeta::cv::ImageData& image,
                const std::vector<SeetaPointF>& points);
    ~DB();
};

#endif // DB_H
